package com.gelian.demo.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.gelian.demo.MainActivity;


public class SpUtils {

    //SharedPreferences使用的固定字段


    private static final String PHONE = "phone";    //手机id
    private static final String USER_PASS = "user_pass";    //用户密码


    private static SharedPreferences sharedPreferences;

    private SpUtils() {
        sharedPreferences = MainActivity.mContext.getSharedPreferences("ge_lian_demo", Context.MODE_PRIVATE);
    }


    private static class SpUtilHolder {
        private static final SpUtils INSTANCE = new SpUtils();
    }

    public static SpUtils getInstance() {
        return SpUtilHolder.INSTANCE;
    }

    /**
     * 保存手机号码
     *
     * @param phone
     */
    public void saveMobileId(String phone) {
        sharedPreferences.edit().putString(PHONE, phone).apply();
    }

    /**
     * 获取phone
     *
     * @return
     */
    public String getMobileId() {
        return sharedPreferences.getString(PHONE, "");
    }

    /**
     * 保存用户的密码
     *
     * @param pass
     */
    public void setUserPass(String pass) {
        sharedPreferences.edit().putString(USER_PASS, pass).apply();
    }

    /**
     * 获取用户密码
     *
     * @return
     */
    public String getUserPass() {
        return sharedPreferences.getString(USER_PASS, "");
    }


}
